<?php

namespace apps\marriage\app\op\controller;

use apps\marriage\core\service\MarketingActivityService;
use think\Request;

class MarketingActivityController extends BaseMarriageOpController
{
    /**
     * @var MarketingActivityService
     */
    private $marketingActivityService;

    protected function init()
    {
        parent::init();
        $this->marketingActivityService = service('MarketingActivity', SERVICE_NAMESPACE);
    }

    public function lists(Request $request)
    {
        $pageSize = $request->param('page_size', 10, 'intval');
        $res = $this->marketingActivityService->pageListByParams([], $pageSize);

        return $this->success($res);
    }

    public function save(Request $request)
    {
        $data = $request->param();
        $this->marketingActivityService->save($data);
        return $this->success();
    }

    public function info(Request $request)
    {
        $id = $request->param('id', 10, 'intval');
        $activity = $this->marketingActivityService->getByPk($id);
        $activity = $this->marketingActivityService->format($activity);
        return $this->success(['activity' => $activity]);
    }

    public function online(Request $request)
    {
        $id = $request->param('id', 10, 'intval');
        $this->marketingActivityService->updateByPk([
            'id' => $id,
            'enable' => 1
        ]);
        return $this->success();
    }

    public function offline(Request $request)
    {
        $id = $request->param('id', 10, 'intval');
        $this->marketingActivityService->updateByPk([
            'id' => $id,
            'enable' => 0
        ]);
        return $this->success();
    }
}